<?php namespace system\service;
/**
 * 用户
 * Class User
 * @package system\service
 */
class User{

    /**
     * 登陆
     * @return bool
     */
    public function login(){
//        检测是否为空
        Validate::make([
            ['username','required','账号不能为空'],
            ['password','required','密码不能为空']
        ]);
//        实例化模型
        $db = new \system\model\User();
        $userData = $db->where('username',Request::post('username'))->first();
//        检测账号密码是否正确
        if(!$userData['username']){
            message('账号密码错误','','error');
        }
        if($userData['password'] != md5(Request::post('password'))){
            message('账号密码错误','','error');
        }
//        修改登录IP和时间
        $userData->loginip = Request::ip();
        $userData->logintime = time();
        $userData->save();
        Session::set('uid',$userData['uid']);
        return true;
    }

    /**
     * 检测是否登陆
     */
    public function isLogin(){
        if(!Session::get( 'uid' )){
            message('请先登录在操作','admin/Entry/logins','warning');
        }
    }


}




